﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:vm="clr-namespace:IISExpressGui.Presentation.ViewModel"
                    xmlns:vw="clr-namespace:IISExpressGui.Presentation.View">

    <!-- 
    This style configures both of the main content areas in the main window.
    -->
    <Style x:Key="MainHCCStyle" TargetType="{x:Type HeaderedContentControl}">
        <Setter Property="HeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Border 
                        Background="{StaticResource Brush_HeaderBackground}" 
                        BorderBrush="LightGray" 
                        BorderThickness="1" 
                        CornerRadius="5" 
                        Margin="4" 
                        Padding="4" 
                        SnapsToDevicePixels="True" 
                        >
                        <TextBlock 
                          FontSize="14"
                          FontWeight="Bold"
                          Foreground="White" 
                          HorizontalAlignment="Center"  
                          Text="{TemplateBinding Content}" 
                          />
                    </Border>
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <!-- 
                This template ensures that content of a HeaderedContentControl 
                fills the available vertical space. 
                -->
                <ControlTemplate TargetType="{x:Type HeaderedContentControl}">
                    <DockPanel>
                        <ContentPresenter 
                            DockPanel.Dock="Top"
                            ContentSource="Header" 
                            ContentTemplate="{TemplateBinding HeaderTemplate}" 
                            />
                        <ContentPresenter 
                            ContentSource="Content" 
                            ContentTemplate="{TemplateBinding ContentTemplate}" 
                            />
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--
    This style ensures that the borders in the main window are consistent.
    -->
    <Style x:Key="MainBorderStyle" TargetType="{x:Type Border}">
        <Setter Property="Background" Value="WhiteSmoke" />
        <Setter Property="BorderBrush" Value="LightGray" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="CornerRadius" Value="5" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
    </Style>

    <!--
    This template explains how to render the contextmenu on the website listbox.
    Used by WebSiteListTemplate
    -->
    <DataTemplate x:Key="ContextMenuItemHeaderTemplate">
        <TextBlock
                x:Name="menuItemTextBlock"  
                Text="Stop" />
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Path=IsRunning}" Value="False">
                <Setter TargetName="menuItemTextBlock" 
                        Property="Text" 
                        Value="Start" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <!--
    This template explains how to render the list of commands on the left
    side in the main window (the 'Control Panel' area).
    -->
    <DataTemplate x:Key="WebSiteListTemplate">
        <ListBox Width="200" 
                 IsTabStop="False" 
                 IsSynchronizedWithCurrentItem="True" 
                 ItemsSource="{Binding}" 
                 Margin="6,2" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock
                            Margin="20,6,3,6" 
                            Text="{Binding Path=Name}" />
                        <TextBlock
                            x:Name="statusTextBlock" 
                            Margin="0,6,3,6" 
                            Text="(running)" />
                        <TextBlock
                            x:Name="unsavedTextBlock" 
                            Visibility="Hidden"
                            Margin="0,6" 
                            Text="*" />
                        <StackPanel.ContextMenu>
                            <ContextMenu  x:Name="menuItemContextMenu"  StaysOpen="true">
                                <MenuItem 
                                    Header="{Binding}"
                                    HeaderTemplate="{StaticResource ContextMenuItemHeaderTemplate}"
                                    Command="{Binding Path=ToggleStatusCommand}"
                                />
                            </ContextMenu>
                        </StackPanel.ContextMenu>
                    </StackPanel>
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding Path=IsRunning}" Value="False">
                            <Setter TargetName="statusTextBlock" 
                                    Property="Text" 
                                    Value="(stopped)" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=IsModified}" Value="True">
                            <Setter TargetName="unsavedTextBlock" 
                                    Property="Visibility" 
                                    Value="Visible" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=IsNewWebSite}" Value="True">
                            <Setter TargetName="statusTextBlock" 
                                    Property="Visibility" 
                                    Value="Collapsed" />
                            <Setter TargetName="menuItemContextMenu" 
                                    Property="Visibility" 
                                    Value="Hidden" />
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </DataTemplate>

    <!--
    This template is for validation error messages
    -->
    <DataTemplate DataType="{x:Type ValidationError}">
        <TextBlock 
          FontStyle="Italic"
          Foreground="Red"
          HorizontalAlignment="Stretch"
          Margin="0,1"
          Text="{Binding Path=ErrorContent}" 
          />
    </DataTemplate>

    <!--
    This template explains how to render the 'Configuration' content area in the main window.
    -->
    <DataTemplate x:Key="WebSiteDetailTemplate">
        <Grid Margin="10,50">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="30"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="30"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="30"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" MinWidth="100"/>
                <ColumnDefinition MaxWidth="325"/>
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.Column="0" 
                   HorizontalAlignment="Right"
                   Content="_Name:" 
                   Target="nameTextBox"/>
            <TextBox x:Name="nameTextBox" Grid.Row="0" Grid.Column="1" 
                     Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}" 
                     HorizontalAlignment="Left" 
                     VerticalAlignment="Center"
                     Width="200"/>
            <Label x:Name="urlLabel" Grid.Row="2" Grid.Column="0" 
                   Content="_Url:" 
                   HorizontalAlignment="Right"
                   Target="portTextBox"/>
            <StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1">
                <TextBlock VerticalAlignment="Center"
                           Text="{Binding Path=Url}" />
                <TextBlock VerticalAlignment="Center"
                           Text=":" />
                <TextBox x:Name="portTextBox" 
                         Margin="3,0,0,0"
                         Text="{Binding Path=Port, ValidatesOnDataErrors=True}" 
                         HorizontalAlignment="Left" 
                         VerticalAlignment="Center"
                         />
            </StackPanel>
            <ContentPresenter Grid.Row="3" Grid.Column="1"
                      Content="{Binding ElementName=portTextBox, Path=(Validation.Errors).CurrentItem}"
                      />
            <Label Grid.Row="4" Grid.Column="0" 
                   Content="_Path:" 
                   HorizontalAlignment="Right"
                   Target="pathTextBox"/>
            <StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="1">
                <TextBox x:Name="pathTextBox" 
                     Text="{Binding Path=PhysicalPath, ValidatesOnDataErrors=True}" 
                     HorizontalAlignment="Left"
                     VerticalAlignment="Center"
                     Width="250"/>
                <Button Content="_Browse" 
                        Command="{Binding Path=BrowseCommand}"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"
                        Margin="4,2"
                        MinWidth="60" />
            </StackPanel>
            <ContentPresenter Grid.Row="5" Grid.Column="1"
                      Content="{Binding ElementName=pathTextBox, Path=(Validation.Errors).CurrentItem}"
                      />
            <Button 
                  Grid.Row="6" Grid.Column="2"
                  Command="{Binding Path=SaveCommand}"
                  Content="_Save"
                  HorizontalAlignment="Right"
                  VerticalAlignment="Top"
                  Margin="4,2,10,2" 
                  MinWidth="60" 
                  />
        </Grid>
    </DataTemplate>

</ResourceDictionary>